/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bean.lazy;

import java.util.ArrayList;
import org.ipti.br.tag.dao.ActorFacade;
import org.ipti.br.tag.entity.Actor;
import java.util.List;
import java.util.Map;
import org.ipti.br.tag.entity.Human;
import org.ipti.br.tag.entity.Person;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
 *
 * @author israel
 */
public class LazyActorDataModel extends LazyDataModel<Actor> {
    private ActorFacade actorDAO;
    
    private List<Long> unities;
    
    private Long personageID;
    
    public LazyActorDataModel(ActorFacade actorDAO, List<Long> unities, Long personageID) {
        super();
        this.actorDAO = actorDAO;
        this.unities = unities;
        this.personageID = personageID;
    }
    
    @Override
    public List<Actor> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
        List<Actor> actors = actorDAO.searchActorActivatedPerPersonageUnities(unities, personageID, first, pageSize, filters);
        return actors;
    }
    
//    public String getPerson(Actor actor) {
//        if (Human.class.isInstance(person)) {
//            return ((Human) person).getName();
//        } else {
//            return "";
//        }
//    }
    
    public String getHumanName(Person person) {
        if (Human.class.isInstance(person)) {
            return ((Human) person).getName();
        } else {
            return "";
        }
    }

    @Override
    public int getRowCount() {
        return actorDAO.getActorCount(unities, personageID);
    }

    public ActorFacade getActorDAO() {
        return actorDAO;
    }

    public void setActorDAO(ActorFacade actorDAO) {
        this.actorDAO = actorDAO;
    }

    public Long getPersonageID() {
        return personageID;
    }

    public void setPersonageID(Long personageID) {
        this.personageID = personageID;
    }

    public List<Long> getUnities() {
        return unities;
    }

    public void setUnities(List<Long> unities) {
        this.unities = unities;
    }   
    
}
